import React from 'react'
import { NavLink, useRoutes} from 'react-router'
import routes from './routes'

export default function App() {
  const element = useRoutes(routes)
  function hightLightClass({isActive}){
    return isActive ? 'list-group-item highLight' : 'list-group-item'
  }
  return (
    <div>
    <div className="row">
      <div className="col-xs-offset-2 col-xs-8">
        <div className="page-header"><h2>React Router Demo</h2></div>
      </div>
    </div>
    <div className="row">
      <div className="col-xs-2 col-xs-offset-2">
        <div className="list-group">
          {/* 路由链接 */}
          <NavLink className={hightLightClass} to="/about">about</NavLink>
          <NavLink className={hightLightClass} to="/home">Home</NavLink>
        </div>
      </div>
      <div className="col-xs-6">
        <div className="panel">
          <div className="panel-body">
            {/* 注册路由,Routes效果同router5中的switch，一个匹配上了就不会再往下匹配，不会出现同时加载两个组件的情况 */}
            {element}
          </div>
        </div>
      </div>
    </div>
  </div>
  )
}
